package views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

import utils.AgendaDay;

import calendar_ex.Appointment;
import calendar_ex.CalendarDate;
import calendar_ex.CalendarEx;

public class Agenda extends JPanel{

	public Agenda(){
		
		this.setPreferredSize(new Dimension(355,500));
		this.setBackground(Color.white);
		this.setLayout(new BorderLayout());
		this.setAlignmentX(CENTER_ALIGNMENT);
		// Title
		JPanel titleBar = new JPanel();
		titleBar.setBackground(Color.white);
		titleBar.setLayout(new GridLayout());
		JLabel title = new JLabel();
		title.setText("<html>&nbsp;&nbsp;&nbsp;<u>Agenda</u></html>");
		title.setFont(new Font("Arial", Font.BOLD, 24));
		titleBar.add(title);
		this.add(titleBar,BorderLayout.NORTH);
		
		// Content
		JPanel content = new JPanel();
		content.setLayout(new BoxLayout(content,BoxLayout.Y_AXIS));
		content.setBackground(Color.WHITE);
		Calendar cal = Calendar.getInstance();
		int cday = cal.get(Calendar.DATE);
		int cmonth = cal.get(Calendar.MONTH) + 1;
		int cyear = cal.get(Calendar.YEAR);
		
		CalendarEx calData = new CalendarEx();
        calData.openCalendar("calendar.txt");
		int daysShown=0;
		int show=7;
		CalendarDate prev=null;
		CalendarDate day = new CalendarDate(cday,cmonth,cyear);
		AgendaDay agendaDay;
		int i=0;
		while(i<show){
			if(prev!=null)
				day = CalendarDate.nextDay(prev);
			System.out.println(day.day+"/"+day.month+"/"+day.year);
			agendaDay = new AgendaDay(day);
			if(!agendaDay.isEmpty()){
				daysShown++;
				content.add(agendaDay);
				content.add(new JSeparator(SwingConstants.HORIZONTAL));
			}
			daysShown++;
			prev = day;
			i++;
		}
		if(daysShown==0){
			JLabel noAgenda = new JLabel("You don't have any events on your agenda for this week!");
			noAgenda.setFont(new Font("Arial", Font.BOLD, 16));
			content.add(noAgenda);
		}
		
		/*while(daysShown<show && itApp.hasNext()){
			Appointment tempApp = (Appointment) itApp.next();
			CalendarDate tempDate = tempApp.date;
			if(dateArchive.contains(CalendarDate.getDateID(tempDate)))
				continue;
			dateArchive.add(CalendarDate.getDateID(tempDate));
			AgendaDay agendaDay = new AgendaDay(tempDate);
			if(!agendaDay.isEmpty()){
				daysShown++;
				content.add(agendaDay);
				content.add(new JSeparator(SwingConstants.HORIZONTAL));
			}
		} */
		this.add(content,BorderLayout.CENTER);
	}  

}


